﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using TaskProject.Application.Command.Production;
using TaskProject.Domain.Production;
using TaskProject.ErrorCode;
using TaskProject.Extension;

namespace TaskProject.Controllers
{
    /// <summary>
    /// 产品
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProductionController : ControllerBase
    {
        IMediator mediator;

        public ProductionController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 负责人
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<LeaderModel>>> GetLeader([FromQuery]GetLeaderCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 生产工单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]   
        public Task<APIResult<List<WorkOrderDTO>>> GetWorkOrder([FromQuery]GetWorkOrderCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 添加工艺流程
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> AddProcess(AddProductProcessCommand request)
        {
            return await mediator.Send(request); 
        }
        /// <summary>
        /// 添加产品信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> AddProduction(AddProductionItemCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 添加生产工单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> AddWorkOrder(AddWorkOrderCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 查询产品
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<ProductItemModel>>> GetProductItem([FromQuery]GetProductItemCommand request)
        {
            return  mediator.Send(request);
        }
        /// <summary>
        /// 添加报工
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> AddReport(AddReportWrokCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 查询单个生产工单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<WorkOrderDTO>> GetWorkOrderOne([FromQuery]GetWorkOrderOneCommand request)
        {
            return  mediator.Send(request);
        }
        /// <summary>
        /// 根据生产工单查询工序成功
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<ProductProcessModel>> GetProcessOne([FromQuery]GetProductProcessCommand request)
        {
            return mediator.Send(request);
        }
    }
}
